package charpter14.lynx;

import static net.mindview.util.Print.print;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Nineteen {
	static void printInfo(Class cc) {
		print("Class name: " + cc.getName() + " is interface? ["
				+ cc.isInterface() + "]");
		print("Simple name: " + cc.getSimpleName());
		print("Canonical name : " + cc.getCanonicalName());
	}

	public static void main(String[] args) {
		Class c = null;
		try {
			c = Class.forName("typeinfo.toys.FancyToy");
		} catch (ClassNotFoundException e) {
			print("Can't find FancyToy");
			System.exit(1);
		}
		printInfo(c);
		for (Class face : c.getInterfaces())
			printInfo(face);
		Class up = c.getSuperclass();
		Object obj = null;
		try {
			// Requires default constructor:
			int i;
			Constructor constructor = up.getDeclaredConstructor(int.class);
			constructor.setAccessible(true);
			obj = constructor.newInstance(1);
			System.out.println(0);
		} catch (InstantiationException e) {
			print("Cannot instantiate");
			System.exit(1);
		} catch (IllegalAccessException e) {
			print("Cannot access");
			System.exit(1);
		} catch (IllegalArgumentException e) {
			print("Illegal Argument");
			System.exit(1);
		} catch (InvocationTargetException e) {
			print("no obj");
			System.exit(1);
		} catch (NoSuchMethodException e) {
			print("no such method.");
			System.exit(1);
		} catch (SecurityException e) {
			print("Security violation.");
			System.exit(1);
		}
		printInfo(obj.getClass());
	}
}